<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>收费项目设置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8"/>
    <link rel="stylesheet" href="../../css/font.css">
    <link rel="stylesheet" href="../../css/xadmin.css">
    <link rel="stylesheet" href="../../lib/layui/css/layui.css" media="all">
    <script src="../../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>

</head>

<body>



<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <div class="am-cf am-padding am-padding-bottom-0">

                        <form class="layui-form layui-col-space5">
                            <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>

            <a>
              <cite>收费项目设置/Charge item setting</cite></a>
          </span>
                                <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
                                   onclick="location.reload()" title="刷新">
                                    <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
                            </div>
                            <br>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="drCode" autocomplete="off" id="drCode"
                                       placeholder="项目编码" class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" id="drName" placeholder="项目名称或拼音首字母" autocomplete="off"
                                       class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>
                                </button>
                            </div>
                        </form>
                    </div>
                    <div class="am-cf am-padding am-padding-bottom-0">
                        <hr>
                        <form class="layui-form layui-col-space5">
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <select name="drRecuperationType" id="drRecuperationType" lay-search=""
                                            lay-filter="drRecuperationType">
                                        <option value="">调理方类型</option>
                                        <option value="17">中药</option>
                                        <option value="18">西药</option>
                                        <option value="19">中成药</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <select name="drType" lay-search="" id="drType" lay-filter="drType">
                                        <option value="">药品类型</option>
                                        <option value="10">袋装</option>
                                        <option value="11">饮片</option>
                                        <option value="12">颗粒</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <select name="sdrState" lay-search="" id="sdrState" lay-filter="sdrState">
                                        <option value="">状态</option>
                                        <option value="15">已启用</option>
                                        <option value="16">已禁用</option>
                                    </select>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="layui-card-header demoTable">
                    <button class="layui-btn" onclick="xadmin.open('新增收费项目','./6.2-add.html',600,600)"><i
                            class="layui-icon"></i>添加
                    </button>
                    <button class="layui-btn layui-btn-danger" data-type="getCheckData"><i class="layui-icon"></i>批量删除
                    </button>
                </div>

                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form" id="demo" lay-filter="demo">
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>

    layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider', 'form'], function () {
        var laydate = layui.laydate //日期
            , laypage = layui.laypage //分页
            , layer = layui.layer //弹层
            , table = layui.table //表格
            , carousel = layui.carousel //轮播
            , upload = layui.upload //上传
            , element = layui.element //元素操作
            , slider = layui.slider //滑块
            , table = layui.table
            , form = layui.form


        //监听提交（根据调理方类型、药品类型和状态查询收费项目）
        form.on('select(sdrState)', function () {
            var drRecuperationType = $('#drRecuperationType').val()
                , drType = $('#drType').val()
                , drState = $('#sdrState').val()
            console.log(drRecuperationType + "--" + drType + "--" + drState);
            $.ajax({
                url: '/JT90/items/selectDrugsByMultipleConditions',//地址
                dataType: 'json',//数据类型
                data: {"drRecuperationType": drRecuperationType, "drType": drType, "drState": drState},
                type: 'GET',//类型
                contentType: 'application/json;charset=UTF-8',
                //请求成功
                success: function () {
                    //分页
                    table.render({
                        elem: '#demo'
                        ,
                        id: 'test'
                        ,
                        height: 286
                        ,
                        url: '/JT90/items/selectDrugsByMultipleConditions?drRecuperationType=' + drRecuperationType + '&drType=' + drType + '&drState=' + drState//数据接口
                        ,
                        page: {
                            count: 100
                            , layout: ['limit', 'count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                            , groups: 5 //只显示 1 个连续页码
                            , first: '首页'//不显示首页
                            , last: '尾页' //不显示尾页
                            , limit: 5
                            , limits: [5, 10, 15, 20]
                            , theme: '#44cc33'
                            , jump: function (obj) {
                                console.log(obj)
                            }
                        }//开启分页
                        ,
                        cols: [[ //表头
                            {type: 'checkbox', fixed: 'left', width: '10%'}
                            , {field: 'drId', title: '项目ID', width: '20%'}
                            , {field: 'drName', title: '项目名', width: '20%'}
                            , {field: 'drCode', title: '项目编码', width: '20%'}
                            , {field: 'drTypeShow', title: '项目类型', width: '15%'}
                            , {field: 'drRecuperationTypeShow', title: '调理方类型', width: '10%'}
                            , {field: 'drSpecs', title: '规格', width: '10%'}
                            , {field: 'drManufactureDate', title: '药品生产日期', width: '20%'}
                            , {field: 'drValidityDate', title: '药品有效期', width: '20%'}
                            , {field: 'drFrequency', title: '药品频次', width: '20%'}
                            , {field: 'drUsage', title: '用法', width: '20%'}
                            , {field: 'drFactory', title: '药品生产厂家', width: '20%'}
                            , {field: 'drUnit', title: '单位', width: '5%'}
                            , {field: 'drRemarks', title: '药品备注', width: '20%'}
                            , {field: 'drPriceSales', title: '售价', width: '20%'}
                            , {field: 'drConsumptionDay', title: '每天用量', width: '20%'}
                            , {field: 'drConsumptionTimes', title: '每次用量', width: '20%'}
                            , {field: 'drProducingArea', title: '原产地', width: '20%'}
                            , {
                                field: 'right', title: '状态', width: '10%', templet: function (d) {
                                    var state = "";
                                    if (d.drState == "15") {
                                        state = "<input type='checkbox' value='" + d.drId + "' id='status' lay-filter='stat' checked='checked' name='status'  lay-skin='switch' lay-text='启用|停用' >";
                                    } else {
                                        state = "<input type='checkbox' value='" + d.drId + "' id='status' lay-filter='stat'  name='status'  lay-skin='switch' lay-text='启用|停用' >";
                                    }
                                    return state;
                                }
                            }
                            , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: '15%'}
                        ]]
                        ,
                        even: true
                    });
                }
            });

            return false;
        });
        form.on('select(drType)', function () {
            var drRecuperationType = $('#drRecuperationType').val()
                , drType = $('#drType').val()
                , drState = $('#sdrState').val()
            console.log(drRecuperationType + "--" + drType + "--" + drState);
            $.ajax({
                url: '/JT90/items/selectDrugsByMultipleConditions',//地址
                dataType: 'json',//数据类型
                data: {"drRecuperationType": drRecuperationType, "drType": drType, "drState": drState},
                type: 'GET',//类型
                contentType: 'application/json;charset=UTF-8',
                //请求成功
                success: function () {
                    //分页
                    table.render({
                        elem: '#demo'
                        ,
                        id: 'test'
                        ,
                        height: 286
                        ,
                        url: '/JT90/items/selectDrugsByMultipleConditions?drRecuperationType=' + drRecuperationType + '&drType=' + drType + '&drState=' + drState//数据接口
                        ,
                        page: {
                            count: 100
                            , layout: ['limit', 'count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                            , groups: 5 //只显示 1 个连续页码
                            , first: '首页'//不显示首页
                            , last: '尾页' //不显示尾页
                            , limit: 5
                            , limits: [5, 10, 15, 20]
                            , theme: '#44cc33'
                            , jump: function (obj) {
                                console.log(obj)
                            }
                        }//开启分页
                        ,
                        cols: [[ //表头
                            {type: 'checkbox', fixed: 'left', width: '10%'}
                            , {field: 'drId', title: '项目ID', width: '20%'}
                            , {field: 'drName', title: '项目名', width: '20%'}
                            , {field: 'drCode', title: '项目编码', width: '20%'}
                            , {field: 'drTypeShow', title: '项目类型', width: '15%'}
                            , {field: 'drRecuperationTypeShow', title: '调理方类型', width: '10%'}
                            , {field: 'drSpecs', title: '规格', width: '10%'}
                            , {field: 'drManufactureDate', title: '药品生产日期', width: '20%'}
                            , {field: 'drValidityDate', title: '药品有效期', width: '20%'}
                            , {field: 'drFrequency', title: '药品频次', width: '20%'}
                            , {field: 'drUsage', title: '用法', width: '20%'}
                            , {field: 'drFactory', title: '药品生产厂家', width: '20%'}

                            , {field: 'drUnit', title: '单位', width: '5%'}
                            , {field: 'drRemarks', title: '药品备注', width: '20%'}
                            , {field: 'drPriceSales', title: '售价', width: '20%'}
                            , {field: 'drConsumptionDay', title: '每天用量', width: '20%'}
                            , {field: 'drConsumptionTimes', title: '每次用量', width: '20%'}
                            , {field: 'drProducingArea', title: '原产地', width: '20%'}
                            , {
                                field: 'right', title: '状态', width: '10%', templet: function (d) {
                                    var state = "";
                                    if (d.drState == "15") {
                                        state = "<input type='checkbox' value='" + d.drId + "' id='status' lay-filter='stat' checked='checked' name='status'  lay-skin='switch' lay-text='启用|停用' >";
                                    } else {
                                        state = "<input type='checkbox' value='" + d.drId + "' id='status' lay-filter='stat'  name='status'  lay-skin='switch' lay-text='启用|停用' >";
                                    }
                                    return state;
                                }
                            }
                            , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: '15%'}
                        ]]
                        ,
                        even: true
                    });
                }
            });

            return false;
        });
        form.on('select(drRecuperationType)', function () {
            var drRecuperationType = $('#drRecuperationType').val()
                , drType = $('#drType').val()
                , drState = $('#sdrState').val()
            console.log(drRecuperationType + "--" + drType + "--" + drState);
            $.ajax({
                url: '/JT90/items/selectDrugsByMultipleConditions',//地址
                dataType: 'json',//数据类型
                data: {"drRecuperationType": drRecuperationType, "drType": drType, "drState": drState},
                type: 'GET',//类型
                contentType: 'application/json;charset=UTF-8',
                //请求成功
                success: function () {
                    //分页
                    table.render({
                        elem: '#demo'
                        ,
                        id: 'test'
                        ,
                        height: 286
                        ,
                        url: '/JT90/items/selectDrugsByMultipleConditions?drRecuperationType=' + drRecuperationType + '&drType=' + drType + '&drState=' + drState//数据接口
                        ,
                        page: {
                            count: 100
                            , layout: ['limit', 'count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                            , groups: 5 //只显示 1 个连续页码
                            , first: '首页'//不显示首页
                            , last: '尾页' //不显示尾页
                            , limit: 5
                            , limits: [5, 10, 15, 20]
                            , theme: '#44cc33'
                            , jump: function (obj) {
                                console.log(obj)
                            }
                        }//开启分页
                        ,
                        cols: [[ //表头
                            {type: 'checkbox', fixed: 'left', width: '10%'}
                            , {field: 'drId', title: '项目ID', width: '20%'}
                            , {field: 'drName', title: '项目名', width: '20%'}
                            , {field: 'drCode', title: '项目编码', width: '20%'}
                            , {field: 'drTypeShow', title: '项目类型', width: '15%'}
                            , {field: 'drRecuperationTypeShow', title: '调理方类型', width: '10%'}
                            , {field: 'drSpecs', title: '规格', width: '10%'}
                            , {field: 'drManufactureDate', title: '药品生产日期', width: '20%'}
                            , {field: 'drValidityDate', title: '药品有效期', width: '20%'}
                            , {field: 'drFrequency', title: '药品频次', width: '20%'}
                            , {field: 'drUsage', title: '用法', width: '20%'}
                            , {field: 'drFactory', title: '药品生产厂家', width: '20%'}

                            , {field: 'drUnit', title: '单位', width: '5%'}
                            , {field: 'drRemarks', title: '药品备注', width: '20%'}
                            , {field: 'drPriceSales', title: '售价', width: '20%'}
                            , {field: 'drConsumptionDay', title: '每天用量', width: '20%'}
                            , {field: 'drConsumptionTimes', title: '每次用量', width: '20%'}
                            , {field: 'drProducingArea', title: '原产地', width: '20%'}
                            , {
                                field: 'right', title: '状态', width: '10%', templet: function (d) {
                                    var state = "";
                                    if (d.drState == "15") {
                                        state = "<input type='checkbox' value='" + d.drId + "' id='status' lay-filter='stat' checked='checked' name='status'  lay-skin='switch' lay-text='启用|停用' >";
                                    } else {
                                        state = "<input type='checkbox' value='" + d.drId + "' id='status' lay-filter='stat'  name='status'  lay-skin='switch' lay-text='启用|停用' >";
                                    }
                                    return state;
                                }
                            }
                            , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: '15%'}
                        ]]
                        ,
                        even: true
                    });
                }
            });

            return false;
        });

        //监听提交（根据名称和编号查询收费项目）
        form.on('submit(sreach)', function () {
            var drName = $('#drName').val(), drCode = $('#drCode').val();
            console.log(drName + "--" + drCode);
            $.ajax({
                url: '/JT90/items/selectDrugsByNameOrPinyinInitials',//地址
                dataType: 'json',//数据类型
                data: {"drName": drName, "drCode": drCode},
                type: 'GET',//类型
                contentType: 'application/json;charset=UTF-8',
                //请求成功
                success: function () {
                    //分页
                    table.render({
                        elem: '#demo'
                        , id: 'test'
                        , height: 286
                        , url: '/JT90/items/selectDrugsByNameOrPinyinInitials?drName=' + drName + '&drCode=' + drCode //数据接口
                        , page: {
                            count: 100
                            , layout: ['limit', 'count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                            , groups: 5 //只显示 1 个连续页码
                            , first: '首页'//不显示首页
                            , last: '尾页' //不显示尾页
                            , limit: 5
                            , limits: [5, 10, 15, 20]
                            , theme: '#44cc33'
                            , jump: function (obj) {
                                console.log(obj)
                            }
                        }//开启分页
                        , cols: [[ //表头
                            {type: 'checkbox', fixed: 'left', width: '10%'}
                            , {field: 'drId', title: '项目ID', width: '20%'}
                            , {field: 'drCode', title: '项目编码', width: '20%'}
                            , {field: 'drName', title: '项目名', width: '20%'}
                            , {field: 'drTypeShow', title: '项目类型', width: '20%'}
                            , {field: 'drRecuperationTypeShow', title: '调理方类型', width: '10%'}
                            , {field: 'drSpecs', title: '规格', width: '10%'}
                            , {field: 'drManufactureDate', title: '药品生产日期', width: '20%'}
                            , {field: 'drValidityDate', title: '药品有效期', width: '20%'}
                            , {field: 'drFrequency', title: '药品频次', width: '20%'}
                            , {field: 'drUsage', title: '用法', width: '20%'}
                            , {field: 'drFactory', title: '药品生产厂家', width: '20%'}
                            , {field: 'drUnitShow', title: '单位', width: '5%'}
                            , {field: 'drRemarks', title: '药品备注', width: '20%'}
                            , {field: 'drPriceSales', title: '售价', width: '20%'}
                            , {field: 'drConsumptionDay', title: '每天用量', width: '20%'}
                            , {field: 'drConsumptionTimes', title: '每次用量', width: '20%'}
                            , {field: 'drProducingArea', title: '原产地', width: '20%'}
                            , {
                                field: 'right', title: '状态', width: '10%', templet: function (d) {
                                    var state = "";
                                    if (d.drState == "15") {
                                        state = "<input type='checkbox' value='" + d.drId + "' id='status' lay-filter='stat' checked='checked' name='status'  lay-skin='switch' lay-text='启用|停用' >";
                                    } else {
                                        state = "<input type='checkbox' value='" + d.drId + "' id='status' lay-filter='stat'  name='status'  lay-skin='switch' lay-text='启用|停用' >";
                                    }
                                    return state;
                                }
                            }
                            , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: '15%'}
                        ]]
                        , even: true
                    });
                }
            });

            return false;
        });
        //分页
        table.render({
            elem: '#demo'
            , id: 'test'
            , height: 286
            , url: '/JT90/items/selectDrugsList' //数据接口
            , page: {
                count: 100
                , layout: ['limit', 'count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                , groups: 5 //只显示 1 个连续页码
                , first: '首页'//不显示首页
                , last: '尾页' //不显示尾页
                , limit: 5
                , limits: [5, 10, 15, 20]
                , theme: '#44cc33'
                , jump: function (obj) {
                    console.log(obj)
                }
            }//开启分页
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left', width: '10%'}
                , {field: 'drId', title: '项目编号', width: '10%'}
                , {field: 'drName', title: '项目名', width: '15%'}
                , {field: 'drCode', title: '项目编码', width: '20%'}
                , {field: 'drTypeShow', title: '项目类型', width: '15%'}
                , {field: 'drRecuperationTypeShow', title: '调理方类型', width: '10%'}
                , {field: 'drSpecs', title: '规格', width: '10%'}
                , {field: 'drManufactureDate', title: '药品生产日期', width: '20%'}
                , {field: 'drValidityDate', title: '药品有效期', width: '20%'}
                , {field: 'drFrequency', title: '药品频次', width: '6.5%'}
                /*, {field: 'drUsage', title: '用法', width: '6.5%'}*/
                , {field: 'drFactory', title: '药品生产厂家', width: '10%'}
                , {field: 'drUnitShow', title: '单位', width: '5%'}
                , {field: 'drRemarks', title: '药品备注', width: '20%'}
                , {field: 'drPriceSales', title: '售价', width: '20%'}
                , {field: 'drConsumptionDay', title: '每天用量', width: '20%'}
                , {field: 'drConsumptionTimes', title: '每次用量', width: '20%'}
                , {field: 'drProducingArea', title: '原产地', width: '20%'}
                , {
                    field: 'drState', title: '状态', width: '10%', templet: function (d) {
                        var state = "";
                        if (d.drState == "15") {
                            state = "<input type='checkbox' value='" + d.drId + "' id='status' lay-filter='stat' checked='checked' name='status'  lay-skin='switch' lay-text='启用|停用' >";
                        } else {
                            state = "<input type='checkbox' value='" + d.drId + "' id='status' lay-filter='stat'  name='status'  lay-skin='switch' lay-text='启用|停用' >";
                        }
                        return state;
                    }
                }
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: '20%'}
            ]]
            , even: true
        });

        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            if (layEvent === 'del') {
                layer.confirm('确认删除这条数据吗？', function (index) {
                    var drId = data.drId;//获取选中行的对象的id值
                    //发异步删除数据
                    $.ajax({
                        url: '/JT90/items/deleteItemById',//地址
                        dataType: 'json',//数据类型
                        data: {"drId": drId},
                        type: 'GET',//类型
                        contentType: 'application/json;charset=UTF-8',
                        //请求成功
                        success: function (map) {
                            if (map.msg) {
                                $(obj).parents("tr").remove();
                                if (map.msg) {
                                    layer.msg('已删除!', {
                                        icon: 1,
                                        time: 1000
                                    });
                                }

                            }
                        }
                    });
                    /*用户-删除*/
                    obj.del();
                    layer.close(index);

                });
            } else if (obj.event === 'edit') {
                var data = obj.data; //获得当前行数据
                /* var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）*/
                var drId = data.drId;//获取选中行的对象的id值
                var drName = data.drName;
                var drCode = data.drCode;
                var drTypeShow = data.drTypeShow;
                if (drTypeShow = '饮片') {
                    var drType = 10;
                } else if (drTypeShow = '颗粒') {
                    drType = 11;
                } else if (drTypeShow = '袋装颗粒') {
                    drType = 12;
                }
                console.log(drType);

                var drRecuperationTypeShow = data.drRecuperationTypeShow;
                if (drRecuperationTypeShow = '中药处方') {
                    var drRecuperationType = 17;
                } else if (drRecuperationTypeShow = '西药处方') {
                    drRecuperationType = 18;
                } else if (drRecuperationTypeShow = '中成药处方') {
                    drRecuperationType = 19;
                }
                console.log(drRecuperationType);
                var drSpecs = data.drSpecs;
                var drManufactureDate = data.drManufactureDate;
                var drValidityDate = data.drValidityDate;
                var drFrequency = data.drFrequency;
                var drUsage = data.drUsage;
                var drFactory = data.drFactory;
                var drUnitShow=data.drUnitShow;
                if (drUnitShow='克'){
                    var drUnit = 1;
                } else if (drUnitShow='千克'){
                    var drUnit = 2;
                } else if (drUnitShow='包'){
                    var drUnit = 3;
                } else if (drUnitShow='盒'){
                    var drUnit = 4;
                } else if (drUnitShow='袋'){
                    var drUnit = 5;
                } else if (drUnitShow='支'){
                    var drUnit = 6;
                } else if (drUnitShow='次'){
                    var drUnit = 7;
                } else if (drUnitShow='片'){
                    var drUnit = 8;
                } else if (drUnitShow='疗程'){
                    var drUnit = 9;
                }


                var drRemarks = data.drRemarks;
                var drPriceSales = data.drPriceSales;
                var drConsumptionTimes = data.drConsumptionTimes;
                var drConsumptionDay = data.drConsumptionDay;
                var drProducingArea = data.drProducingArea;


                //编辑弹窗事件
                layer.open({
                    type: 2,
                    area: ['600px', '400px'],
                    title: '修改收费项目',
                    content: 'http://122.51.140.205:8892/JT90/index/6BasicArchives/6.2-edit.html?drId=' + drId + '&drName=' + drName + '&drCode=' + drCode + '&drType=' + drType + '&drRecuperationType=' + drRecuperationType + '&drSpecs=' + drSpecs + '&drManufactureDate=' + drManufactureDate + '&drValidityDate=' + drValidityDate + '&drFrequency=' + drFrequency + '&drUsage=' + drUsage + '&drFactory=' + drFactory + '&drUnit=' + drUnit + '&drRemarks=' + drRemarks + '&drPriceSales=' + drPriceSales + '&drConsumptionDay=' + drConsumptionDay + 'drConsumptionTimes=' + drConsumptionTimes + '&drProducingArea=' + drProducingArea,
                    success: function () {
                        var body = layer.getChildFrame('body');//获取弹窗页面
                        body.find('#drId').val(drId);
                        body.find('#drName').val(drName);
                        body.find('#drCode').val(drCode);
                        body.find('#drType').val(drType);
                        body.find('#drRecuperationType').val(drRecuperationType);
                        body.find('#drSpecs').val(drSpecs);
                        body.find('#drManufactureDate').val(drManufactureDate);
                        body.find('#drValidityDate').val(drValidityDate);
                        body.find('#drFrequency').val(drFrequency);
                        body.find('#drUsage').val(drUsage);
                        body.find('#drFactory').val(drFactory);
                        body.find('#drUnit').val(drUnit);
                        body.find('#drRemarks').val(drRemarks);
                        body.find('#drPriceSales').val(drPriceSales);
                        body.find('#drConsumptionDay').val(drConsumptionDay);
                        body.find('#drConsumptionTimes').val(drConsumptionTimes);
                        body.find('#drProducingArea').val(drProducingArea);
                    }

                });

            }
        });
        //监听状态开关
        form.on('switch(stat)', function (obj) {
            var drId = this.value;
            var boolean = obj.elem.checked;
            if (boolean) {
                var drState = 15;
            } else {
                drState = 16;
            }
            console.log(drId + "---" + drState);
            $.ajax({
                url: '/JT90/items/updateItemStateById',//地址
                dataType: 'json',//数据类型
                data: {"drId": drId, "drState": drState},
                type: 'GET',//类型
                contentType: 'application/json;charset=UTF-8',
                //请求成功
                success: function (map) {
                    if (map.msg) {
                        if (map.data.drState == 15) {
                            layer.alert("已启用", {
                                icon: 6
                            })
                        } else {
                            layer.alert("已停用", {
                                icon: 6
                            })
                        }
                        console.log(map.data);
                    }
                    return false;
                },
                //失败/超时
                error: function () {
                    alert('請求超時');
                    //alert(errorThrown);
                }
            });
        });


        //监听表格复选框选择
        table.on('checkbox(demo)', function (obj) {
            console.log(obj.data)
        });
        //批量删除
        var $ = layui.$, active = {
            getCheckData: function (obj) { //获取选中数据
                var checkStatus = table.checkStatus('test')
                    , data = checkStatus.data;
                if (data == 0) {
                    layer.msg('至少选择一个', {icon: 2});

                    return;
                }
                var checkList = "";
                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        checkList += data[i].drId + ",";
                    }
                    console.log(checkList);
                }
                layer.confirm('确认要删除吗？', function () {
                    $.ajax({
                        url: '/JT90/items/deleteDrugsById',//地址
                        dataType: 'json',//数据类型
                        data: {"checkList": checkList},
                        type: 'GET',//类型
                        contentType: 'application/json;charset=UTF-8',
                        //请求成功
                        success: function (map) {
                            if (map.msg) {
                                if (map.msg) {
                                    layer.msg('已删除!', {
                                        icon: 1,
                                        time: 1500,
                                        end: function () {
                                            location.reload();
                                        }
                                    });
                                }

                            }

                        }
                    });

                });

            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


    });

</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
</html>